<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="经营人" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入场所经营人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场所地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入场所地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挂牌状态" prop="address">
        <el-select v-model="queryParams.cardsZtSearch" placeholder="请选择挂牌状态" clearable>
          <el-option
            v-for="item in cardZtSearchList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="管辖单位名称" prop="jurisdictions">
        <el-select v-model="queryParams.jurisdictions" placeholder="请选择管辖单位名称" clearable>
          <el-option
            v-for="dict in dict.type.ptsj_jurisdiction"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
    
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ptsj:place:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ptsj:place:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ptsj:place:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ptsj:place:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="placeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="场所编号" align="center" prop="placeCode" /> -->
      <el-table-column label="场所名称" align="center" prop="placeName" />
      <!-- <el-table-column label="房源类型;0 网约房 1 民宿" align="center" prop="houseType" /> -->
      <!-- <el-table-column label="管理模式" align="center" prop="manageMode" /> -->
      <!-- <el-table-column label="管辖单位代码" align="center" prop="gxdwdm" /> -->
      <el-table-column label="管辖单位名称" align="center" prop="jurisdictions">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ptsj_jurisdiction" :value="scope.row.jurisdictions"/>
        </template>
      </el-table-column>
      <el-table-column label="经营状况" align="center" prop="status">
        <template slot-scope="scope">
          <div>
            {{ scope.row.status == '2' ? '正常' : '不正常' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="星级" align="center" prop="stars" />
      <el-table-column label="积分" align="center" prop="score" />
      <el-table-column label="挂牌情况" align="center" prop="cardstatus">
        <template slot-scope="scope">
          <div>
            <span style="color: #409EFF">蓝:{{scope.row.blue }} </span>
            <span style="color: #E6A23C">黄:{{scope.row.yellow }} </span>
            <span style="color: #F56C6C">红:{{scope.row.red }}</span>
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="蓝牌;0 无 1 蓝牌 2 黄牌 3 红牌" align="center" prop="blue" />
      <el-table-column label="黄牌" align="center" prop="yellow" />
      <el-table-column label="红牌" align="center" prop="red" />
      <el-table-column label="挂牌状态;0 无 1 待挂牌" align="center" prop="cardstatus" />
      <el-table-column label="所在地区" align="center" prop="area" />
      <el-table-column label="街道" align="center" prop="street" />
      <el-table-column label="门牌号" align="center" prop="houseNumber" />
      <el-table-column label="小区/建筑物" align="center" prop="cell" />
      <el-table-column label="楼栋" align="center" prop="building" />
      <el-table-column label="单元" align="center" prop="unit" /> -->
      <el-table-column label="详细地址" align="center" prop="address" />
      <!-- <el-table-column label="经营人类型" align="center" prop="ownerType" /> -->
      <el-table-column label="经营人" align="center" prop="ownerName" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <!-- <el-table-column label="单位信用代码" align="center" prop="certNumber" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ptsj:place:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="seeDetails(scope.row)"
          >详情</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ptsj:place:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改单位信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="场所名称" prop="placeName">
          <el-input v-model="form.placeName" placeholder="请输入场所名称" />
        </el-form-item>
        <el-form-item label="管理模式" prop="manageMode">
          <el-input v-model="form.manageMode" placeholder="请输入管理模式" />
        </el-form-item>
        <el-form-item label="管辖单位代码" prop="gxdwdm">
          <el-input v-model="form.gxdwdm" placeholder="请输入管辖单位代码" />
        </el-form-item>
        <el-form-item label="管辖单位名称" prop="jurisdictions">
          <el-select v-model="form.jurisdictions" placeholder="请选择管辖单位名称">
            <el-option
              v-for="dict in dict.type.ptsj_jurisdiction"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="星级" prop="stars">
          <el-input v-model="form.stars" placeholder="请输入星级" />
        </el-form-item>
        <el-form-item label="积分" prop="score">
          <el-input v-model="form.score" placeholder="请输入积分" />
        </el-form-item>
        <el-form-item label="蓝牌;0 无 1 蓝牌 2 黄牌 3 红牌" prop="blue">
          <el-input v-model="form.blue" placeholder="请输入蓝牌;0 无 1 蓝牌 2 黄牌 3 红牌" />
        </el-form-item>
        <el-form-item label="黄牌" prop="yellow">
          <el-input v-model="form.yellow" placeholder="请输入黄牌" />
        </el-form-item>
        <el-form-item label="红牌" prop="red">
          <el-input v-model="form.red" placeholder="请输入红牌" />
        </el-form-item>
        <el-form-item label="所在地区" prop="area">
          <el-input v-model="form.area" placeholder="请输入所在地区" />
        </el-form-item>
        <el-form-item label="街道" prop="street">
          <el-input v-model="form.street" placeholder="请输入街道" />
        </el-form-item>
        <el-form-item label="门牌号" prop="houseNumber">
          <el-input v-model="form.houseNumber" placeholder="请输入门牌号" />
        </el-form-item>
        <el-form-item label="小区/建筑物" prop="cell">
          <el-input v-model="form.cell" placeholder="请输入小区/建筑物" />
        </el-form-item>
        <el-form-item label="楼栋" prop="building">
          <el-input v-model="form.building" placeholder="请输入楼栋" />
        </el-form-item>
        <el-form-item label="单元" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单元" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经营人" prop="ownerName">
          <el-input v-model="form.ownerName" placeholder="请输入经营人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="单位信用代码" prop="certNumber">
          <el-input v-model="form.certNumber" placeholder="请输入单位信用代码" />
        </el-form-item>
        <el-form-item label="删除标记" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPlace, getPlace, delPlace, addPlace, updatePlace } from "@/api/ptsj/place";

export default {
  name: "Place",
  dicts: ['ptsj_jurisdiction'],
  data() {
    return {
      cardZtSearchList:[
        {
          label:'无挂牌',
          value:'无挂牌'
        },
        {
          label:'蓝牌',
          value:'蓝牌'
        },
        {
          label:'黄牌',
          value:'黄牌'
        },
        {
          label:'红牌',
          value:'红牌'
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 单位信息表格数据
      placeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        placeName: null,
        houseType: null,
        manageMode: null,
        gxdwdm: null,
        jurisdictions: null,
        status: null,
        stars: null,
        score: null,
        blue: null,
        yellow: null,
        red: null,
        cardstatus: null,
        area: null,
        street: null,
        houseNumber: null,
        cell: null,
        building: null,
        unit: null,
        address: null,
        ownerType: null,
        ownerName: null,
        phone: null,
        certNumber: null,
        createdBy: null,
        createdTime: null,
        cardsZtSearch:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  filters: {
    filterGpqk(val) {
      if(val == '1') {
        return '蓝牌'
      } else if(val == '2') {
        return '黄牌'
      } else if(val == '3') {
        return '红牌'
      } else {
        return '无挂牌'
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询单位信息列表 */
    getList() {
      this.loading = true;
      listPlace(this.queryParams).then(response => {
        this.placeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        placeCode: null,
        placeName: null,
        houseType: null,
        manageMode: null,
        gxdwdm: null,
        jurisdictions: null,
        status: null,
        stars: null,
        score: null,
        blue: null,
        yellow: null,
        red: null,
        cardstatus: null,
        area: null,
        street: null,
        houseNumber: null,
        cell: null,
        building: null,
        unit: null,
        address: null,
        ownerType: null,
        ownerName: null,
        phone: null,
        certNumber: null,
        delFlag: null,
        createdBy: null,
        createdTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },

    /* 查看详情 */
    seeDetails(row) {
      // this.$router.push({path: '/see/place-details', query: { placeCode: row.placeCode }});
      this.$router.push({path: '/place/detail', query: { placeCode: row.placeCode }});
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.placeCode)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加单位信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const placeCode = row.placeCode || this.ids
      getPlace(placeCode).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改单位信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.placeCode != null) {
            updatePlace(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlace(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const placeCodes = row.placeCode || this.ids;
      this.$modal.confirm('是否确认删除单位信息编号为"' + placeCodes + '"的数据项？').then(function() {
        return delPlace(placeCodes);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ptsj/place/export', {
        ...this.queryParams
      }, `place_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
